/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#include "CameraObject.h"
#include "SceneObject.h"

namespace PQClient
{
	CameraObject::CameraObject(SceneObject* scene)
		: GameObject(scene,GAME_OBJECT_CAMERA),_camera(0)
	{
		this->setName("Camera Object");
		
		_camera=scene->getSceneManager()->createCamera("Camera"+Ogre::StringConverter::toString(getId()));
		_sceneNode->attachObject(_camera);
		
		Ogre::RenderWindow* window=scene->getRenderWindow();
		window->removeAllViewports();
		_viewport= window->addViewport(_camera);
		_viewport->setBackgroundColour(scene->getRenderProperty().getBackground());
        _camera->setAspectRatio(Ogre::Real(_viewport->getActualWidth())/Ogre::Real(_viewport->getActualHeight()));

	}


	void CameraObject::resetViewport()
	{
		Ogre::RenderWindow* window=_sceneObject->getRenderWindow();
		window->removeAllViewports();
		_viewport= window->addViewport(_camera);
		_viewport->setBackgroundColour(_sceneObject->getRenderProperty().getBackground());
        _camera->setAspectRatio(Ogre::Real(_viewport->getActualWidth())/Ogre::Real(_viewport->getActualHeight()));

	}

	
}
